package com.twu.biblioteca.session.actions;

import com.twu.biblioteca.Book;
import com.twu.biblioteca.session.Session;
import com.twu.biblioteca.session.SessionAction;
import com.twu.biblioteca.session.SessionOption;

public class CheckoutBookAction extends SessionAction{


    public CheckoutBookAction(SessionOption option, Session session) {
        super(option, session);
    }

    @Override
    public String[] getActionInput() {
        return this.getSession().getUi().readBookDetails();
    }

    @Override
    public void performAction(String[] args) {

        for (Book book : this.getSession().getLibrary().getBooks()) {
            if (book.compareWithDetails(args[0], args[1], args[2])) {
                book.setCheckedOut(true);
                this.getSession().getCurrentlyLoggedIn().getCheckedOutItems().add(book);
                this.getSession().getUi().successBookCheckout();
                return;   //Don't Checkout all copies, just one
            }
        }
        this.getSession().getUi().unavailableBook();
    }
}
